package com.dc.commons.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

public class SpringBeanFactory implements BeanFactoryAware{

	private static BeanFactory beanFactory;
	
	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		SpringBeanFactory.beanFactory=beanFactory;
	}
	
	public static BeanFactory getBeanFactory(){
		return beanFactory;
	}
	public static <T>T getBean(Class<T> t){
		 return (T)beanFactory.getBean(t);
	}
	
	@SuppressWarnings("unchecked")
	public static <T>T getBean(String beanName){
		 return (T)beanFactory.getBean(beanName);
	}
	
	public static <T>T getBean(Class<T> clazz,String beanName){
		 return (T)beanFactory.getBean(beanName, clazz);
	}
}
